package com.yaodian.service.impl;



import com.yaodian.mapper.StaffMapper;
import com.yaodian.pojo.Staff;
import com.yaodian.service.StaffService;
import com.yaodian.vo.StaffVo;
import com.yaodian.vo.UpdateStaffVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * (Staff)表服务实现类
 *
 * @author makejava
 * @since 2025-01-19 11:07:41
 */
@Service
public class StaffServiceImpl implements StaffService {
    @Resource
    private StaffMapper staffMapper;
    @Override
    public Map<String, Object> selectStaff(StaffVo staffVo) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("msg", "查询员工列表成功");
        if (staffVo.getName() == null) {
            staffVo.setName("%%");
        } else {
            staffVo.setName('%' + staffVo.getName() + '%');
        }
        if (staffVo.getAddress() == null) {
            staffVo.setAddress("%%");
        } else {
            staffVo.setAddress('%' + staffVo.getAddress() + '%');
        }
        List<Staff> staffList = staffMapper.selectStaffs(staffVo);
        map.put("data", staffList);
        return map;
    }

    @Override
    public Map<String,Object> insert(StaffVo staffVo) {
        Staff staff = new Staff();
        BeanUtils.copyProperties(staffVo,staff);
        staffMapper.insertStaff(staff);
        HashMap<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg","员工添加成功");
        map.put("data", staff);
        return map;
    }

    @Override
    public Map<String, Object> updateById(UpdateStaffVo updateStaffVo) {
        HashMap<String, Object> map = new HashMap<>();
        staffMapper.updateById(updateStaffVo);
        map.put("code", 200);
        map.put("mag","更新员工信息成功");
        return map;
    }

    @Override
    public Map<String, Object> deleteById(Integer id) {
        HashMap<String, Object> map = new HashMap<>();
        staffMapper.deleteById(id);
        map.put("code", 200);
        map.put("msg","删除成功");
        return map;
    }


}
